﻿using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace ZTreeDome.Util
{
    public class SqlUtil
    {
        public static readonly string connString = ConfigurationManager.ConnectionStrings["Default"].ToString();
        public static DataTable GetDataTable(string connString, string sqlText, CommandType type,
            params SqlParameter[] para)
        {
            DataTable dt = new DataTable("Position");
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    cmd.CommandText = sqlText;
                    cmd.CommandType = type;
                    cmd.Parameters.AddRange(para);
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                }
            }

            return dt;
        }
    }
}